<template>
  <div class="course">
    <div class="top">
      <div class="header">
        <span>特色课</span>
        <van-icon @click="$router.push('/search')" name="search" />
      </div>
      <van-dropdown-menu>
        <van-dropdown-item v-model="value" title="分类">
          <div class="cate">
            <button>重置</button>
            <button class="que">确认</button>
          </div>
        </van-dropdown-item>
        <van-dropdown-item @click="sort" v-model="value" title="排序" :options="options" />
        <van-dropdown-item title="筛选">
          <ul class="shaixuan">
            <li
              :class="{active:active==index}"
              @click="check(item.id,index)"
              v-for="(item,index) in Classify"
              :key="index"
            >{{item.name}}</li>
          </ul>
        </van-dropdown-item>
      </van-dropdown-menu>
    </div>
    <div>
      <course-list v-for="(item,index) in list" :key="index" :itemObj="item"></course-list>
    </div>
  </div>
</template>
<script>
import { reactive, toRefs } from "vue";
import { getCourseBasis, getCourseClassify } from "../../request/home";
import courseList from "../../components/courseList.vue";
export default {
  components: { courseList },
  setup(props) {
    const data = reactive({
      options: [
        { text: "综合排序", value: 0 },
        { text: "最新", value: 1 },
        { text: "最热", value: 2 },
        { text: "价格从高到低", value: 3 },
        { text: "价格从低到高", value: 4 }
      ],
      value: "",
      params: {
        course_type: 0,
        limit: 15,
        page: 1,
        order_by: 0
      },

      list: [],
      Classify: [],
      active: 0
    });
    getCourseBasis({ params: data.params }).then(res => {
      console.log(res);
      data.list = res.data.data.list;
    });
    getCourseClassify().then(res => {
      console.log(res);
      data.Classify = res.data.data.appCourseType;
    });
    const check = (id, i) => {
      data.active = i;
      data.params.course_type = id;
      getCourseBasis({ params: data.params }).then(res => {
        console.log(res);
        data.list = res.data.data.list;
      });
    };
    const sort = () => {
      data.params.order_by = data.value;
      getCourseBasis({ params: data.params }).then(res => {
        console.log(res);
        data.list = res.data.data.list;
      });
    };
    return { ...toRefs(data), check, sort };
  }
};
</script>
<style lang="scss" scoped>
.course {
  background: #f2f3f5;
  height: 100%;
  .top {
    .header {
      background: #ffffff;
      height: 54px;
      text-align: center;
      align-items: center;
      display: flex;
      padding: 0 30px;
      span {
        width: 90%;
        text-align: center;
      }
    }
  }
}
.cate {
  width: 100%;
  height: 120px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 50px;
  button {
    width: 40%;
    height: 45px;
    outline: none;
    border: 1px solid #1989fa;
    background: #fff;
    border-radius: 3px;
    font-size: 20px;
  }
  .que {
    background: #eb6100;
    color: #fff;
    border: none;
  }
}
.shaixuan {
  display: flex;
  flex-wrap: wrap;
  li {
    width: 99px;
    height: 47px;
    background: #f5f5f5;
    font-size: 14px;
    text-align: center;
    line-height: 47px;
    border-radius: 5px;
    margin: 15px 17px;
  }
  .active {
    background: #ebeefe;
    color: #eb6100;
  }
}
</style>